package client.face;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;

import client.PhotoLiveEvent;

/**
 * 项目名称：client.face
 * 创建人:LuoFG
 * 创建时间:2023/2/23  14:27
 * 描述:
 * 作用:
 */
public class FaceClient {

    private static class InstanceHolder {
        private static FaceClient instance = new FaceClient();
    }

    private static FaceClient getInstance() {
        return FaceClient.InstanceHolder.instance;
    }

    public static FaceClient getClient() {
        return getInstance();
    }

    private Bitmap bitmapFace;
    private Bitmap bitmapCropFace;
    private TakeFaceResult takeFaceResult;
    public static PhotoLiveEvent<FaceState> doFaceState = new PhotoLiveEvent<>();//人脸检测界面操作
    private boolean isShowResult = false;
    private boolean isBtnBlue = false;
    private boolean isShowRotate = false;//旋转

    public enum FaceState {
        TYPE_FINISH,
        TYPE_RESET
    }

    public FaceClient setDefault() {
        isShowResult = false;
        isBtnBlue = false;
        isShowRotate = false;//旋转
        return this;
    }

    public FaceClient startActivity(Activity activity) {
        clear();
        activity.startActivity(new Intent(activity, FaceCameraActivity.class));
        return this;
    }

    public void clear() {
        bitmapCropFace = null;
        bitmapFace = null;
    }

    public FaceClient setBtnBlue(boolean btnBlue) {
        isBtnBlue = btnBlue;
        return this;
    }

    public boolean isBtnBlue() {
        return isBtnBlue;
    }

    public FaceClient setFaceState(FaceState faceState) {
        doFaceState.postValue(faceState);
        return this;
    }

    public void takeFacePhotoResult(Activity activity) {
        if (takeFaceResult != null) {
            takeFaceResult.resultFace(activity, bitmapCropFace);
        }
    }

    public interface TakeFaceResult {
        void resultFace(Activity activity, Bitmap bitmap);
    }

    public FaceClient setTakeFaceResult(TakeFaceResult takeFaceResult) {
        this.takeFaceResult = takeFaceResult;
        return this;
    }

    public boolean isShowResult() {
        return isShowResult;
    }

    public FaceClient setShowResult(boolean showResult) {
        isShowResult = showResult;
        return this;
    }

    public Bitmap getBitmapFace() {
        return bitmapFace;
    }

    public Bitmap getBitmapCropFace() {
        return bitmapCropFace;
    }

    public FaceClient setBitmapFace(Bitmap bitmapFace) {
        this.bitmapFace = bitmapFace;
        return this;
    }

    public FaceClient setBitmapCropFace(Bitmap bitmapCropFace) {
        this.bitmapCropFace = bitmapCropFace;
        return this;
    }

    public boolean isShowRotate() {
        return isShowRotate;
    }

    public FaceClient setShowRotate(boolean showRotate) {
        isShowRotate = showRotate;
        return this;
    }
}
